import 'package:flutter/material.dart';

mixin WordItem {
  Size layout(BuildContext context, double maxWidth, double maxHeight);
}

class TextItem with WordItem {
  final TextSpan text;
  final TextDirection direction;

  TextItem({this.text, this.direction = TextDirection.ltr});

  @override
  Size layout(BuildContext context, double maxWidth, double maxHeight) {
    var textPainter = TextPainter(textDirection: direction);
    textPainter.text = this.text;
    textPainter.layout(
      maxWidth: maxHeight,
    );
    return textPainter.size;
  }
}

class ImageItem with WordItem {
  final ImageProvider provider;
  final BoxFit boxFit;
  final double width;
  final double height;

  ImageItem({
    this.provider,
    this.boxFit,
    this.width,
    this.height,
  });

  @override
  Size layout(BuildContext context, double maxWidth, double maxHeight) {
    return Size(width, height);
  }
}
